import {fhirSearchApi,fhirHistoryApi,fhirDeleteApi} from "../../api/modules/fhirApi";
import {createPatientApi, updatePatientApi} from "../../api/modules/patientApi";

export default {
  state: {
    patientList: [],
    messagesJson:""
  },
  mutations: {
    setPatientList(state, data) {
      state.patientList = data;
    }
  },
  actions: {
    getPatientList({commit, rootState}, params) {
      return fhirSearchApi(params).then(res => {
       // alert( JSON.stringify(res.data))
        commit('setPatientList', res.data.entry ? res.data.entry : [{resource:res.data}])
      }).catch(res =>{
        commit('setPatientList',[]);
      })
    },
    getHistoryPatientList({commit, rootState}, params) {
      return fhirHistoryApi(params).then(res => {
        commit('setPatientList', res.data.entry ? res.data.entry : [{resource:res.data}])
      })
    },
    updatePatient({commit, rootState}, params) {
      return updatePatientApi(params);
    },
    createPatient({commit, rootState}, params) {
      return createPatientApi(params);
    },
    deletePatient({commit, rootState}, params) {
      return fhirDeleteApi(params);
    }
  }
}
